<!DOCTYPE html>
<html>
<head>
<title></title>

<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">

<!-- If your application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8"
	src="BufferAudioPlugin.js"></script>
<script type="text/javascript" charset="utf-8" src="streaming.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.1.8.3.min.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery-1.9.2.ui.js"></script>
<script type="text/javascript" charset="utf-8"
	src="jquery.mobile-1.2.0.min.js"></script>

<link rel="stylesheet" href="index.css" type="text/css">
<link rel="stylesheet" href="jquery.mobile-1.1.0.min.css"
	type="text/css">

<link rel="stylesheet"
	href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"
	type="text/css">



<script type="text/javascript">
	var radioURL = 'http://live.str3am.com:2410/wypr';
	document.addEventListener("deviceready", onDeviceReady, false);

	/* When this function is called, Cordova has been initialized and is ready to roll */
	/* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
	see http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
	for more details -jm */

	//http://live.str3am.com:2410/wypr
	//http://stream.radiosai.net:8002/
	//http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 
	function onDeviceReady(){
		playRadio();
 		startTextStreaming();
 		document.addEventListener("backbutton", backKeyDown, true);
 	}

	//function onBackKey() {
	function backKeyDown() {
		stopRadio();
		// We are going back to home so remove the event listener 
		// so the default back key behaviour will take over
		navigator.app.exitApp();
	}

	function playRadio() {
		//navigator.notification.alert("Preparing to play");
		BufferAudioPlugin.bufferRadioFunc(nativePluginResultHandler,
				nativePluginErrorHandler, radioURL);
	}

	function stopRadio() {
		BufferAudioPlugin.stopRadioFunc(nativePluginResultHandler,
				nativePluginErrorHandler, radioURL);
		stopTextStreaming();
	}

	function nativePluginResultHandler(result) {
		//alert("SUCCESS: \r\n"+result );
	}

	function nativePluginErrorHandler(error) {

	}
</script>
</head>


<body>
	<div data-role="page" id="NprHomePage">
		<div data-role="header">
			<h1>Listen live to NPR radio!</h1>
			<a href="#" data-role="button" class="ui-btn-right"
				data-inline="true" data-mini="true" data-theme="b"
				onclick="backKeyDown(); return false" rel="external">Exit</a>

		</div>
		<div data-role="content">
			<!-- a href="#" data-role="button" id="playButton"
				onclick="stopRadio(); return false" rel="external">Stop Radio!</a-->
			<div id="hiddenElemData" class="hiddenCaptions"></div>
			<div id="elemData" class="captions"></div>
		</div>
 
	</div>
</body>
</html>
